package com.wesley.spring.entity;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * LifecycleBeanSample
 * 演示Spring Bean 生命周期
 * @author WangPanYong
 * @since 2021/08/18 14:46
 */
public class LifecycleBeanSample implements BeanNameAware, BeanClassLoaderAware, BeanFactoryAware, InitializingBean, DisposableBean {

    @Autowired
    User user;

    public LifecycleBeanSample() {
        System.out.println("====> LifecycleBeanSample 构造方法:" + user);
        System.out.println("====> LifecycleBeanSample 构造方法");
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        System.out.println("====> LifecycleBeanSample setBeanClassLoader");
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("====> LifecycleBeanSample setBeanFactory");
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("====> LifecycleBeanSample setBeanName");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("====> LifecycleBeanSample afterPropertiesSet");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("====> LifecycleBeanSample destroy");
    }

    @PostConstruct
    public void postConstruct() {
        System.out.println("====> LifecycleBeanSample postConstruct注解方法");
    }

    public void initMethod() {
        System.out.println("====> LifecycleBeanSample initMethod");
    }

    public void destroyMethod() {
        System.out.println("====> LifecycleBeanSample destroyMethod");
    }
}
